package com.woniu.supermarket.web;

import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.impl.WarehousingDetailServiceImpl;
import com.woniu.supermarket.vo.WarehousingDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("warehousingDetail")
@Api(value = "商品入库单详情操作")
public class WarehousingDetailController {

    @Autowired
    WarehousingDetailServiceImpl iWarehousingDetailService;

    @GetMapping("/showWarehousingDetail/{id}")
    @ApiOperation(value = "通过入库订单id查询订单详情信息")
    public ResultResponse<List<WarehousingDetailVo>> showWarehousingDetail(@PathVariable("id")Integer id){
        System.out.println(id+"===id");
        ResultResponse<List<WarehousingDetailVo>> result = null;
        try {
            List<WarehousingDetailVo> lists = iWarehousingDetailService.findAllWarehousingDetailByWarehousingId(id);
            result = new ResultResponse<>(200,"查询入库单详情成功",lists);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询入库单详情失败");
        }
        return result;
    }


    @GetMapping("/showWarehousingDetailOfWarehousing/{warehousingNumber}")
    @ApiOperation(value = "审核订单，修改订单审核状态")
    public ResultResponse<List<WarehousingDetailVo>> showWarehousingDetailOfWarehousing(@PathVariable String warehousingNumber) {
        ResultResponse<List<WarehousingDetailVo>> result = null;
        try {
            List<WarehousingDetailVo> lists = iWarehousingDetailService.findAllWarehousingDetailByWarehousingNumber(warehousingNumber);
            if(lists!=null){
                result = new ResultResponse<>(200,"查询入库单详情成功",lists);
            }else{
                result = new ResultResponse<>(201,"查询入库单详情失败");
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            result = new ResultResponse<>(555,"系统错误");
        }
        return result;
    }

}
